#ifndef AES_H
#define AES_H
#include <qstring.h>
#include <qmath.h>
#include <cstdlib>
#include <iostream>

class AES
{
public:
    AES(unsigned char* key);
    virtual ~AES();
    unsigned char* Cipher(unsigned char* input);	//加密
    unsigned char* InvCipher(unsigned char* input);	//解密
    void* Cipher(void* input, int length=0);
    void* InvCipher(void* input, int length);

    QString input;
    QString output;
    QByteArray input2;
    QByteArray output2;
    int aes_pading;//填充的0的个数
    int aes_rounds;//加解密的轮数
    void Initialize();//初始化，填充，确定加、解密轮数

    void aes_encrypt();//AES加密
    void aes_decrypt();//AES解密
private:
    unsigned char Sbox[256];	//s盒
    unsigned char InvSbox[256];	//p盒
    unsigned char w[11][4][4];	//轮密钥

    void KeyExpansion(unsigned char* key, unsigned char w[][4][4]);	//密钥扩展
    unsigned char FFmul(unsigned char a, unsigned char b);

    void SubBytes(unsigned char state[][4]);	//字节代替，s盒
    void ShiftRows(unsigned char state[][4]);	//行移位
    void MixColumns(unsigned char state[][4]);	//列混合
    void AddRoundKey(unsigned char state[][4], unsigned	char k[][4]);	//异或轮密钥

    void InvSubBytes(unsigned char state[][4]);
    void InvShiftRows(unsigned char state[][4]);
    void InvMixColumns(unsigned char state[][4]);
    void print(unsigned char* state);
};


#endif // AES_H
